﻿/*******************************************************
* Autor: Oleg Rukin aka Keyki
********************************************************/

using System.Runtime.Serialization;
using System.Xml;

namespace Keyki.InitData
{
	[DataContract]
	public struct SInitData
	{
		private static DataContractSerializer _serializer;

		[DataMember]
		public int FeatureCount;
		[DataMember]
		public int LinguisticVariables;
		[DataMember]
		public string[] LinguisticVariablesNames;
		[DataMember]
		public string[] ClassNames;
		[DataMember]
		public int ClassCount;
		[DataMember]
		public int ElementCount;
		[DataMember]
		public int ParamsCount;
		[DataMember]
		public int RullesCount;
		[DataMember]
		public float LearnPercent;
		[DataMember]
		public double LearnCount;
		[DataMember]
		public bool IsAny;
		[DataMember]
		public bool IsSafeState;
		[DataMember]
		public bool IsDynamicStep;
		[DataMember]
		public bool Randomize;
		[DataMember]
		public bool NoRepeats;
		[DataMember]
		public string FileName;

		[DataMember]
		public string FuzzySetHandler;
		[DataMember]
		public string AntecedentsHandler;
		[DataMember]
		public string InitDataHandler;
		[DataMember]
		public string ChooseRuleHandler;
		[DataMember]
		public string TrainerHandler;
		[DataMember]
		public string WorkerHandler;

		[DataMember]
		public float Sigma;
		[DataMember]
		public int MaxEpouch;
		[DataMember]
		public float MaxError;


		static public void Serialize(ref SInitData initData, string filename)
		{
			var settings = new XmlWriterSettings
			                             	{
			                             		Indent = true,
			                             		IndentChars = "  ",
			                             		NewLineOnAttributes = true
			                             	};
			XmlWriter writer = XmlWriter.Create(filename, settings);

			_serializer = new DataContractSerializer(typeof(SInitData));
			_serializer.WriteObject(writer,initData);

			writer.Close();
		}


		static public void Deserialize(ref SInitData initData, string filename)
		{
			XmlReader reader = new XmlTextReader(filename);
			_serializer = new DataContractSerializer(typeof(SInitData));
			var rez = _serializer.ReadObject(reader);

			initData = (SInitData)rez;

			reader.Close();
		}

	}
}